package lyx.tank.stages
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.events.TimerEvent;
	import flash.geom.Matrix;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.utils.Timer;
	
	import lyx.game.GameEngine;
	import lyx.game.stage.GameStage;
	import lyx.utils.log.Logger;
	
	public class LevelInStage extends GameStage
	{
		private var _view:Bitmap;
		public var level_name:String="NONE";
		
		public function LevelInStage()
		{
			
		}
		
		override protected function initGameStageView():void
		{
			_view = new Bitmap(new BitmapData(640,480,true,0));
			addChild(_view);
			
			var title:TextField = new TextField();
			title.autoSize = TextFieldAutoSize.LEFT;
			title.background = true;
			title.backgroundColor = 0x909090;
			title.text = "Stage "+level_name;
			var text_format:TextFormat = new TextFormat();
			text_format.size = 20;
			title.setTextFormat(text_format);
			
			_view.bitmapData.draw(title,new Matrix(1,0,0,1,260,200));
		}
		
		override protected function initGameStageEvent():void
		{
			var timer:Timer = new Timer(2000,1);
			timer.addEventListener(TimerEvent.TIMER,timerHandler);
			timer.start();
			
			Logger.getInstance().debug("Going to begin stage "+level_name);
		}
		
		override protected function destoryGameStageEvent():void
		{
			
		}
		
		private function timerHandler(event:TimerEvent):void
		{
			Timer(event.target).removeEventListener(TimerEvent.TIMER,timerHandler);
			
			GameEngine.getInstance().switchGameStage(GameingStage,{'level_name':level_name});
		}
	}
}